package org.example;


import org.example.bean.SpringConfig;
import org.example.bean.TimeTaskService;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class App {
    public static void main(String[] args) throws InterruptedException {
        // 初始化Spring注解配置的IOC容器
        AnnotationConfigApplicationContext context =
                new AnnotationConfigApplicationContext(SpringConfig.class);

        // 获取任务服务Bean
        TimeTaskService taskService = context.getBean(TimeTaskService.class);

        // 提交任务到线程池执行
        taskService.executeTimePrintTask(10);  // 10秒的定时输出任务
        taskService.executeCountdownTask(60);  // 60秒的倒计时任务
        taskService.executeTimePrintTask(15);  // 15秒的定时输出任务

        // 等待所有任务完成
        Thread.sleep(65000);

        // 关闭线程池和Spring容器
        taskService.shutdownThreadPool();
        context.close();

        System.out.println("程序执行完毕");
    }
}